package cn.datacare.orm.mapper.parameter;


import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static cn.datacare.orm.util.Separator.COMMA;

/**
 * insert 操作的时候，参数命名
 * @author Evan
 */
public class InsertParameter extends MapperParameter {
	
	public InsertParameter(Method m, String annoParam){
		super(m,annoParam);
		preCheck();
	}

	protected void preCheck(){
		if(this.annoParam!=null&&annoParam.length()!=0){
			paramsName = annoParam.split(COMMA);
		}else{
			this.paramsName = checkFirst(m);
		}
		
	}
	
	
	@Override
	public Object get(Object[] array) {
		if(array==null||array.length==0){
			return Collections.EMPTY_MAP;
		}
		Map<String,Object> map = new HashMap<>(array.length);
		for(int i=0;i<array.length;i++){
			map.put(this.paramsName[i], array[i]);
		}
		this.addRoot(map, array[0]);
		return map;
	}
}
